{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "list assignment index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-1-200fdc5dfd6f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mIndexError\u001b[0m: list assignment index out of range"
     ]
    }
   ],
   "source": [
    "a=[1,2,3,4]\n",
    "a[4]=5\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5, 2, 3, 4]\n",
      "[5, 2, 3, 4, 10]\n",
      "[5, 2, 3, 4, 10, 11]\n",
      "[5, 2, 3, 4, 10, 11, [12, 14]]\n",
      "[5, 2, 3, 4, 10, 11, [12, 14], [3]]\n",
      "[5, 2, 3, 4, 10, 11, [12, 14], [3], 5]\n",
      "[2, 3, 4, 10, 11, [12, 14], [3], 5]\n"
     ]
    },
    {
     "ename": "AttributeError",
     "evalue": "'list' object has no attribute 'push'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-9-36315f7f8f4f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     14\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     15\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 16\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpush\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     17\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'list' object has no attribute 'push'"
     ]
    }
   ],
   "source": [
    "a=[1,2,3,4]\n",
    "a[0]=5\n",
    "print(a)\n",
    "a.append(10)\n",
    "print(a)\n",
    "a.extend([11])\n",
    "print(a)\n",
    "a.append([12,14])\n",
    "print(a)\n",
    "a.extend([[3]])\n",
    "print(a)\n",
    "a.append(5)\n",
    "print(a)\n",
    "a.remove(5)\n",
    "print(a)\n",
    "a.pop(5)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['a', 'bdg', 'cdfg', 'u']\n"
     ]
    }
   ],
   "source": [
    "s=\"a    bdg cdfg u\"\n",
    "l=s.split()\n",
    "print(l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 -0.66 7.899\n",
      "[-0.66, 1, 7.899]\n"
     ]
    }
   ],
   "source": [
    "l1=input().split()\n",
    "l2=[eval(i) for i in l1]\n",
    "l2.sort()\n",
    "print(l2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "234565\n",
      "gbfvdcx \n",
      "-=-['p;/.\n",
      "5\n",
      "['234565', 'gbfvdcx ', \"-=-['p;/.\", '5']\n"
     ]
    }
   ],
   "source": [
    "lst=[input() for i in range(4)]\n",
    "print(lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'j' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-19-f5f1a543aca5>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mc\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mj\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mc\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'j' is not defined"
     ]
    }
   ],
   "source": [
    "c=1+2*j\n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "addrest 18.63818383216858s\n"
     ]
    }
   ],
   "source": [
    "from time import time\n",
    "from random import random\n",
    "start=time()\n",
    "lst=[]\n",
    "for i in range(100000):\n",
    "    lst=lst+[random()]\n",
    "print(\"addrest\",str(time()-start)+\"s\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "addrest 0.0289766788482666s\n"
     ]
    }
   ],
   "source": [
    "start=time()\n",
    "lst=[]\n",
    "for i in range(100000):\n",
    "    lst.append(random())\n",
    "print(\"appendrest\",str(time()-start)+\"s\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "addrest 2.8346002101898193s\n"
     ]
    }
   ],
   "source": [
    "start=time()\n",
    "lst=[]\n",
    "for i in range(100000):\n",
    "    lst.insert(0,random)\n",
    "print(\"listrest\",str(time()-start)+\"s\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "listexprest 0.013959884643554688s\n"
     ]
    }
   ],
   "source": [
    "start=time()\n",
    "lst=[random() for i in range(100000)]\n",
    "print(\"listexprest\",str(time()-start)+\"s\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 2, 3, 4)\n",
      "4\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "'tuple' object does not support item assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-28-348ef16996bd>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
     ]
    }
   ],
   "source": [
    "a=(1,2,3,4)\n",
    "print(a)\n",
    "print(a[3])\n",
    "a[3]=5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1305900569440\n",
      "<class 'int'>\n"
     ]
    }
   ],
   "source": [
    "b=id(a)\n",
    "print(b)\n",
    "print(type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3180102988 褚好\n",
      "3170102465 王凯亮\n",
      "3160104456 李永\n",
      "3171104169 陈鑫\n",
      "318400429 徐杭诚\n",
      "\n",
      "3180102988 褚好\n",
      "3170102465 王凯亮\n",
      "3160104456 李永\n",
      "3171104169 陈鑫\n",
      "318400429 徐杭诚\n",
      "\n",
      "3180102988 褚好\n",
      "3170102465 王凯亮\n",
      "3160104456 李永\n",
      "3171104169 陈鑫\n",
      "318400429 徐杭诚\n"
     ]
    }
   ],
   "source": [
    "students=[(3180102988,\"褚好\"),(3170102465,\"王凯亮\"),(3160104456,\"李永\"),(3171104169,\"陈鑫\"),(318400429,\"徐杭诚\")]\n",
    "\n",
    "for row in students: #按行存取\n",
    "    print(row[0],row[1])\n",
    "print()\n",
    "\n",
    "for id,name in students: #按行拆包存取\n",
    "    print(id,name)\n",
    "print()\n",
    "\n",
    "for index in range(len(students)):  #按索引存取\n",
    "    print(students[index][0],students[index][1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.5039\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "n=10000\n",
    "l=[random.randint(0,1) for i in range(n)]\n",
    "print(sum(l)/n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8 2\n"
     ]
    }
   ],
   "source": [
    "m=18\n",
    "n=100\n",
    "while(m%n):\n",
    "    m,n=n,m%n\n",
    "print(m,n)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "cnt=0\n",
    "ave=0\n",
    "while(True):\n",
    "    a=int(input())\n",
    "    if(a==-1):\n",
    "        break\n",
    "    if a%2==0:\n",
    "        cnt+=1\n",
    "        ave+=a\n",
    "ave=ave/cnt\n",
    "print(cnt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "-1\n",
      "4 5.0\n"
     ]
    }
   ],
   "source": [
    "cnt=0 \n",
    "ave=0 \n",
    "while(True): \n",
    "    a=int(input()) \n",
    "    if(a==-1):\n",
    "        break\n",
    "    if a%2==0:\n",
    "        cnt+=1\n",
    "        ave+=a\n",
    "ave=ave/cnt\n",
    "print(cnt,ave)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n",
      "Not Prime\n"
     ]
    }
   ],
   "source": [
    "a=int(input())\n",
    "flag=True\n",
    "for i in range(2,a,1):\n",
    "    if(a%i==0):\n",
    "        flag=False\n",
    "        break\n",
    "if(flag):\n",
    "    print(\"Prime\")\n",
    "else :\n",
    "    print(\"Not Prime\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12\n",
      "[1, 2, 3, 4, 6, 12]\n"
     ]
    }
   ],
   "source": [
    "a=int(input())\n",
    "lst=[i for i in range(1,a+1,1) if a%i==0]\n",
    "print(lst)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
